<?php
require(__META_CONTROLS_GEN__ . '/RoleMetaControlGen.class.php');

/**
 * This is a MetaControl customizable subclass, providing a QForm or QPanel access to event handlers
 * and QControls to perform the Create, Edit, and Delete functionality of the
 * Role class.  This code-generated class extends from
 * the generated MetaControl class, which contains all the basic elements to help a QPanel or QForm
 * display an HTML form that can manipulate a single Role object.
 *
 * To take advantage of some (or all) of these control objects, you
 * must create a new QForm or QPanel which instantiates a RoleMetaControl
 * class.
 *
 * This file is intended to be modified.  Subsequent code regenerations will NOT modify
 * or overwrite this file.
 *
 * @package My QCubed Application
 * @subpackage MetaControls
 */
class RoleMetaControl extends RoleMetaControlGen {
    // Initialize fields with default values from database definition
    /*
		public function __construct($objParentObject, Role $objRole) {
			parent::__construct($objParentObject,$objRole);
			if ( !$this->blnEditMode ){
				$this->objRole->Initialize();
			}
		}
    */
    public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
        $intId = QApplication::PathInfo(0);

        return RoleMetaControl::Create($objParentObject,  QS_DECODE($intId), $intCreateType);
    }
    public function lstRolesAsManr_Create($strControlId = null) {
        $this->lstRolesAsManr = new AutoCompleteList($this->objParentObject, $strControlId);
        $this->lstRolesAsManr->Name = QApplication::Translate('Manage');
        $objAssociatedArray = $this->objRole->GetRoleAsManrArray();
        $objRoleArray = Role::LoadAll();
        if ($objRoleArray) foreach ($objRoleArray as $objRole) {
                foreach ($objAssociatedArray as $objAssociated) {
                    if ($objAssociated->Id == $objRole->Id)
                        $this->lstRolesAsManr->lst->AddItem($objRole->__toString(), $objRole->Id);
                }
            }
        $this->lstRolesAsManr->strCallList = "Role_Change";
        $this->lstRolesAsManr->strReverseCall = "Role_Reverse";
        return $this->lstRolesAsManr;
    }
    protected function lstRolesAsManr_Update() {
        if ($this->lstRolesAsManr) {
            $this->objRole->UnassociateAllRolesAsManr();
            $imax = $this->lstRolesAsManr->lst->__get("ItemCount"); 
            for ($i=0; $i <$imax; $i++) {
                $objListItem = $this->lstRolesAsManr->lst->GetItem($i);
                $this->objRole->AssociateRoleAsManr(Role::Load($objListItem->Value));
            }

        }
    }
}
?>